package com.woniuxy.threeprojcet.end_water_project_admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniuxy.threeprojcet.end_water_project_admin.dao.UserMapper;
import com.woniuxy.threeprojcet.end_water_project_admin.domain.Repair;
import com.woniuxy.threeprojcet.end_water_project_admin.dao.RepairMapper;
import com.woniuxy.threeprojcet.end_water_project_admin.domain.User;
import com.woniuxy.threeprojcet.end_water_project_admin.domain.form.RePairForm;
import com.woniuxy.threeprojcet.end_water_project_admin.service.IRepairService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 维修表 服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2021-08-26
 */
@Service
public class RepairServiceImpl extends ServiceImpl<RepairMapper, Repair> implements IRepairService {

    @Resource
    private RepairMapper repairMapper;
    @Resource
    private UserMapper userMapper;
    @Override
    public IPage getRepair(IPage page) {
//        QueryWrapper queryWrapper = new QueryWrapper();
//        queryWrapper.orderByAsc("submit_time");
//        IPage iPage = repairMapper.selectPage(page, queryWrapper);
        IPage<RePairForm> repair = repairMapper.getRepair(page);

//        List<Repair> repairs = repairMapper.selectList(queryWrapper);

        return repair;
    }

    @Override
    public boolean updateState(int repairId) {

        Repair repair = new Repair();
        repair.setRepairId(repairId);
        repair.setState(1);
        int i = repairMapper.updateById(repair);

        return i>0? true:false;
    }

    @Override
    public User findUserAddress(int waterMeterId) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("water_meter_id",waterMeterId);
        User user = userMapper.selectOne(queryWrapper);

        return user;
    }
}
